// @FileName  :time.c
// @Time      :2024/6/23 14:32
// @Author    :YKW
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>
typedef struct info{
    char id[20];
    int h1,h2,m1,m2,s1,s2,cnt;
    double len;
}info;
info all[1000];
int h(char a){
    if(a=='B')return 1;
    if(a=='M')return 2;
    return 3;
}
int cmp(const void* a, const void* b){
    if(((info*)a)->id[0]==((info*)b)->id[0])
        return ((info*)a)->len>((info*)b)->len;
    else return h(((info*)a)->id[0])-h(((info*)b)->id[0]);
}
int main() {
    int n,ccnt=0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++,ccnt++){
        scanf("%s%d%d%d%d%d%d",all[ccnt].id,&all[ccnt].h1,&all[ccnt].m1,&all[ccnt].s1,&all[ccnt].h2,&all[ccnt].m2,&all[ccnt].s2);
        all[ccnt].len=(all[ccnt].h2-all[ccnt].h1)*3600+(all[ccnt].m2-all[ccnt].m1)*60+all[ccnt].s2-all[ccnt].s1;
        all[ccnt].len=(double)all[ccnt].len/3600.0;
        all[ccnt].cnt++;
        for(int j=0;j<ccnt;j++){
            if(strcmp(all[ccnt].id,all[j].id)==0){
                all[j].len+=all[ccnt].len;
                all[j].cnt++;
                all[ccnt].cnt--;
                ccnt--;
            }
        }
    }
    qsort(all,ccnt,sizeof(info),cmp);
    for(int i=0;i<ccnt;i++){
        printf("%s %.2lf %d\n",all[i].id,all[i].len,all[i].cnt);
    }

}
/*
28
B230330 06 00 08 07 02 56
B230326 06 00 10 06 31 09
M220160 06 30 02 07 02 56
B230312 06 50 03 07 12 56
D230126 07 00 02 07 25 01
M220126 07 00 03 07 30 08
B230101 09 30 00 10 31 05
B230330 10 00 07 11 00 10
B230326 10 00 10 11 30 00
M220126 14 05 06 15 06 25
B230330 15 00 07 16 00 10
B230326 15 00 10 16 00 15
D220028 16 00 05 18 30 09
M230507 16 30 06 17 38 56
D210037 17 00 00 17 47 39
D220012 17 00 01 17 47 40
D230126 17 03 56 18 15 55
B230108 17 59 58 19 02 10
B230312 18 00 00 19 02 07
B230101 18 00 01 19 02 06
B230102 18 00 02 19 02 08
D210037 18 02 00 18 40 22
D220012 18 02 05 18 35 56
M230507 19 00 35 20 30 23
B230326 20 00 10 21 33 01
M220126 20 05 03 22 04 01
M220156 20 05 06 22 04 05
M220160 20 05 08 22 04 03
*/